package logobj.btd;

import logobj.config.ConfProperties;
import logobj.dao.LogDao;
import logobj.dataAnalysis.AnalysisLog;
import logobj.utils.OutLog;
import java.io.File;
import java.util.Map;

public class AnalysisInsertDB {

    public void analylog(String analylogpath){
        LogDao logDao = null;
        File subdir = new File(analylogpath);
        File[] files = subdir.listFiles();
        AnalysisLog analysisLog = null;
        Map<String , Object> strmap = null;
        int updaterow = 0;
        int updateall = 0;
        for(int i= 0 ;i < files.length ; i++){
            analysisLog = new AnalysisLog();
            logDao = new LogDao();
            strmap = analysisLog.loadLog(files[i].getAbsolutePath());
            analysisLog = null;
            OutLog.printf("日志分析完成,开始数据入库->"+files[i].getAbsolutePath());
            updaterow = logDao.insertData(strmap,updaterow);
            updateall +=updaterow;
            logDao = null;
            strmap = null;
            System.gc();
            try {
                Thread.sleep(1000 * ConfProperties.file_insertdb_interval_time);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if(updateall > ConfProperties.data_insert_maxrow){
                break;
            }
        }
    }


}
